﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BestTrader.Cms.UserCenter.Models;
using Microsoft.Extensions.Logging;
using BestTrader.Cms.IServices;
using BestTrader.Cms.Services;
using Microsoft.AspNetCore.Authorization;

namespace BestTrader.Cms.UserCenter.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        public String RealName
        {
            get
            {
                return User.Claims.FirstOrDefault(x => x.Type == "RealName")?.Value;
            }
        }
        //private readonly ILogger<HomeController> _logger;

        //public HomeController(ILogger<HomeController> logger) {
        //    this._logger = logger;
        //}

        /// <summary>
        /// 主界面
        /// </summary>
        public  IActionResult Index()
        {
            ViewData["RealName"] = RealName;
            
            return View();
        }

        /// <summary>
        /// 控制中心
        /// </summary>
        public IActionResult Main()
        {
            ViewData["LoginCount"] = User.Claims.FirstOrDefault(x => x.Type == "LoginCount")?.Value;
            ViewData["LoginLastIp"] = User.Claims.FirstOrDefault(x => x.Type == "LoginLastIp")?.Value;
            ViewData["LoginLastTime"] = User.Claims.FirstOrDefault(x => x.Type == "LoginLastTime")?.Value;

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
